package com.clarte.model;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
public class User implements Serializable{

	private static final long serialVersionUID = 8232303006828430622L;
	@Id
	@GeneratedValue
	private Integer id;
	@Column(unique = true,nullable=false)
	private String username;
	private String password;
	private String cardId;
	private String name;
	private String nativeAddress;
	private String homeAddress;
	private String tel;
	private String memo;
	@ManyToOne(cascade={CascadeType.PERSIST,CascadeType.MERGE},fetch=FetchType.LAZY)
	@JoinColumn(name = "dept_id")
	private Dept dept;

	@ManyToMany(cascade={CascadeType.ALL})
	@Fetch(FetchMode.SUBSELECT)
	private Set<Role> roles;
	
	@ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.PERSIST,CascadeType.MERGE})
	@JoinColumn(name="p_id")
	private User puser;
	
	@OneToMany(mappedBy="user")
	@Fetch(FetchMode.SUBSELECT)
	private Set<ProductSaleInfo> saleInfo;
	
	@OneToMany(mappedBy="user")
	@Fetch(FetchMode.SUBSELECT)
	private Set<FeeInfo> feeInfo;
	
	@OneToOne(fetch=FetchType.LAZY,cascade={CascadeType.ALL})
	@JoinColumn(name="employee_id")
	private Employee employee;

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public Set<FeeInfo> getFeeInfo() {
		return feeInfo;
	}

	public void setFeeInfo(Set<FeeInfo> feeInfo) {
		this.feeInfo = feeInfo;
	}

	public Set<ProductSaleInfo> getSaleInfo() {
		return saleInfo;
	}

	public void setSaleInfo(Set<ProductSaleInfo> saleInfo) {
		this.saleInfo = saleInfo;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getCardId() {
		return cardId;
	}

	public void setCardId(String cardId) {
		this.cardId = cardId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getNativeAddress() {
		return nativeAddress;
	}

	public void setNativeAddress(String nativeAddress) {
		this.nativeAddress = nativeAddress;
	}

	public String getHomeAddress() {
		return homeAddress;
	}

	public void setHomeAddress(String homeAddress) {
		this.homeAddress = homeAddress;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getMemo() {
		return memo;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public Dept getDept() {
		return dept;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}

	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	public User getPuser() {
		return puser;
	}

	public void setPuser(User puser) {
		this.puser = puser;
	}
}
